package com.pams.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.cron.task.Task;
import com.pams.pojo.entity.Tasks;
import com.pams.result.Result;
import com.pams.service.TaskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/tasks")
public class TaskController {

    @Autowired
    TaskService taskService;
    @PutMapping("/add")
    public Result add(@RequestBody Tasks tasks) {
        taskService.add(tasks);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Tasks>> list() {
        List<Tasks> list = taskService.list();
        return Result.success(list);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除事务")
    public Result delete(@RequestParam Long id) {
        taskService.delete(id);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("更新事务")
    public Result update(@RequestBody Tasks tasks) {
        taskService.update(tasks);
        return Result.success();
    }

    @PostMapping("/updateStatus")
    @ApiOperation("状态更新")
    public Result updateStatus(@RequestParam Long id , @RequestParam Integer status) {
        taskService.updateStatus(id ,status);
        return Result.success();
    }

    @GetMapping("/")
    public  Result<Tasks> getTaskById(@RequestParam Long id) {
        Tasks task = taskService.getTaskById(id);
        return Result.success(task);
    }

    @GetMapping("/today")
    public Result<List<Tasks>> getTodayTask() {
        List<Tasks> list = taskService.getTodayTask();
        return Result.success(list);
    }


    @GetMapping("/todayStatus")
    public Result  getStatusToday(@RequestParam("day")   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime day){
       String Status = taskService.getStatusToday(day) ;
        return Result.success(Status);
    }
}













